<?php
require './WeChat.class.php';

$appid="wx77736d01b426da1b";//这里请填你真实的参数值
$appsecret="e2647b0432df44d21b08f84e4f85185e";//这里请填你真实的参数值
$token="weixin";//这里请填你真实的参数值

$wx=new WeChat($appid,$appsecret,$token);

//验证url
// $wx->firstValid();

//判断消息类型
$result=$wx->responseMsg();

if($result['type']=='text'){
    //文本消息
    transmitText($result['obj'], '你发送的是文本，内容为：'.$result['obj']->Content);
}




/*
 * 接收文本消息
 */
function receiveText($object)
{
    $content = "你发送的是文本，内容为：".$object->Content;
    $result = $this->transmitText($object, $content);
    return $result;
}

/*
 * 回复文本消息
 */
function transmitText($object, $content)
{
    $textTpl = "<xml>
        <ToUserName><![CDATA[%s]]></ToUserName>
        <FromUserName><![CDATA[%s]]></FromUserName>
        <CreateTime>%s</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[%s]]></Content>
        </xml>";
    $result = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content);
    file_put_contents('./test.txt',$result);
    echo $result;die;
    // return $result;
}